package com.api.shopapi.mapper;


import com.api.shopapi.entity.VerificationCode;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface VerificationCodeMapper {

    @Insert("insert into verification_code " +
            "(" +
            "VerificationCodeCode," +
            "Phone," +
            "loginName," +
            "RegCode," +
            "GetPwdCode,"+
            "IP,"+
            "CreateTime"+
            ") " +
            "value" +
            "(" +
            "#{verificationCode.VerificationCodeCode}," +
            "#{verificationCode.Phone}," +
            "#{verificationCode.loginName}," +
            "#{verificationCode.RegCode}," +
            "#{verificationCode.GetPwdCode}," +
            "#{verificationCode.Ip}," +
            "#{verificationCode.CreateTime}" +
            ")")
    public int insert(@Param("verificationCode") VerificationCode verificationCode);

    @Delete("delete from verification_code where VerificationCodeCode=#{verificationCodeCode}")
    public int delete(@Param("verificationCodeCode") String verificationCodeCode);

    @Update("update verification_code" +
            " set " +
            " Phone = #{verificationCode.Phone}," +
            " loginName = #{verificationCode.loginName}," +
            " RegCode = #{verificationCode.RegCode}," +
            " GetPwdCode = #{verificationCode.GetPwdCode}," +
            " Ip = #{verificationCode.Ip}"+
            " where VerificationCodeCode=#{verificationCode.VerificationCodeCode}")
    public int update(@Param("verificationCode") VerificationCode verificationCode);

    @Select("select * from verification_code order by CreateTime desc")
    public List<VerificationCode> getList();

    @Select("select * from verification_code where VerificationCodeCode=#{verificationCodeCode} limit 1")
    public VerificationCode getByVerificationCodeCode(@Param("verificationCodeCode") String verificationCodeCode);

    @Select("select * from verification_code where Phone=#{phone} limit 1")
    VerificationCode getByPhone(@Param("phone") String phone);

    @Select("select * from verification_code where loginName=#{loginName} and Phone=#{phone} limit 1")
    VerificationCode getByLoginNamePhone(@Param("loginName") String loginName,@Param("phone") String phone);


}
